<?php

require_once APPLICATION_PATH. '/../library/Zend/Mail.php';
require_once APPLICATION_PATH. '/../library/Zend/Mail/Transport/Smtp.php';

class Uuch_Mail2
{
	private static $_config = array(
		'auth'=>'login',
		'username'=>'serviceuuch@gmail.com',
		'password'=>'youqiuuch!@#',
		'ssl' => 'ssl',
		'port' => 465
	);
	// private static $_config = array(
	// 	'auth'=>'login',
	// 	'username'=>'service@uuch.com',
	// 	'password'=>'uuch.com123',
	// 	'ssl' => 'tls',
	// 	'port' => 587
	// );
	private static $_mail = null;
	private static $_transport = null;

	public function __construct($title, $body)
	{

	}

	public static function SendMail($title,$body,$receive){
		try {
			$shijie=date('Y-m-d');

			$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com',self::$_config);
            //Zend_Mail::setDefaultTransport($transport);
			$mail = new Zend_Mail('UTF-8');				
			$mail->setFrom(self::$_config['username'], self::$_config['auth']);
			$mail->addTo($receive['email'],$receive['name']);
			$mail->setSubject($title,'utf-8');
			$mail->setBodyText($body,'utf-8');
			$mail->send($transport);   
			return true;
		}catch(Exception $e)
		{
            throw $e;
			$e->getTrace();
			return false;
		}
		return false;
	}

	/**
	 * 返回邮箱后缀名
	 * @param string $email
	 */
	public static function getEmailName($email)
	{
		$emailName = substr($email, strpos($email, '@')+1);
		
		return $emailName;
	}
	
	/**
	 * 返回邮箱登录页
	 * @param string $emailName
	 */
	public static function getEmailLoginUrl($emailName)
	{
		$emailUrl = "";
		
		switch($emailName)
		{
			case '163.com':
				$emailUrl = "http://mail.163.com/";
				break;
			case '139.com':
				$emailUrl = "http://mail.10086.cn/";
				break;
			case 'sohu.com':
				$emailUrl = "http://mail.sohu.com/";
				break;
			case 'qq.com':
				$emailUrl = "https://mail.qq.com/cgi-bin/loginpage";
				break;
			case '189.cn':
				$emailUrl = "http://webmail19.189.cn/webmail/";
				break;
			case '126.com':
				$emailUrl = "http://www.126.com/";
				break;
			case 'gmail.com':
				$emailUrl = "http://gmail.google.com/";
				break;	
			case 'sina.com':
				$emailUrl = "http://mail.sina.com.cn/";
				break;
			case 'live.com':
			case 'hotmail.com':
				$emailUrl = "www.hotmail.com";
				break;
			case 'yahoo.com.cn':
			case 'yahoo.cn':
				$emailUrl = "http://mail.cn.yahoo.com/";				
				break;		
			case 'tom.cn':
				$emailUrl = "http://mail.tom.com/";
				break;	
			case 'sogou.com':
				$emailUrl = "http://mail.sogou.com/";
				break;
			case 'eyou.com':
				$emailUrl = "http://www.eyou.com/";
				break;
			case '21cn.com':
				$emailUrl = "http://mail.21cn.com/";
				break;
			case '188.com':
				$emailUrl = "http://www.188.com/";
				break;
			case 'yeah.net':
				$emailUrl = "http://www.yeah.net/";
				break;
			case 'foxmail.com':
				$emailUrl = "http://mail.qq.com/cgi-bin/loginpage?t=fox_loginpage";
				break;
			case 'wo.com.cn':
				$emailUrl = "http://mail.wo.com.cn/mail/login.action";
				break;
			case '263.net':
				$emailUrl = "http://www.263.net/";
				break;
				
			default:
				$emailUrl = "http://www.baidu.com/s?wd=".$emailName;
				break;
		}
		
		return $emailUrl;
	}
	
	public function __destruct() {

	}
}